var express = require('express');
var router = express.Router();
var ManagerModel = require('../models/manager');
var ApplicantModel = require('../models/applicant');
router.post('/', function(req, res, next) {
  var phone = req.body.phone;
  if(req.cookies.token){
    ManagerModel.find({token:req.cookies.token},function(err,data){
      if(data.length>0){
        ApplicantModel.findOneAndRemove({phone:phone},function(err,data){
          if(err){
            return err;
          }
          console.log(data);
          if(data['name']){
            res.json({success:true});
          }else{
            res.json({success:false});
          }
        })
      }else{
        res.json({success:false});
      }
    })
  }else{
    res.redirect(302,'login');
  };
});
module.exports = router;